<template>
	<view class="page">
		<u--form
			labelPosition="top"
			:model="basicForm"
			ref="hmform"
			:rules="rules"
			labelWidth="auto"
			:labelStyle="{
				fontSize: '14px',
				color: '#B2B2B2',
				lineHight: '20px'
			}"
		>
			<view class="basic-style">
				<view class="basic-title basic-border">基础信息</view>
				<u-form-item label="单据编号" prop="billNo">
				  <u--input disabled placeholder="请输入单据编号" v-model="basicForm.billNo"></u--input>
				</u-form-item>
				<u-form-item
					label="申请人"
					prop="employeeId_dictText"
					:borderBottom="false"
				>
					<u--input
						disabled
						placeholder="请选择申请人"
						v-model="basicForm.employeeId_dictText"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="人员编号"
					prop="employeeNo"
					:borderBottom="false"
				>
					<u--input
						v-model="basicForm.employeeNo"
						disabled
						placeholder="请输入人员编号"
						border="surround"
					></u--input>
				</u-form-item>
				<u-form-item
					label="性别"
					prop="gender"
					:borderBottom="false"
				>
					<h-dict-select
						style="width: 100%" 
						v-model="basicForm.gender" 
						disabled
						placeholder="请选择性别" 
						dictName="gender" 
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></h-dict-select>
				</u-form-item>
				<u-form-item
					label="出生日期"
					prop="birthday"
					:borderBottom="false"
				>
					<u--input
						v-model="birthday"
						disabled
						placeholder="请选择出生日期"
						border="surround"
						suffixIcon="calendar-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item label="岗位序列" prop="positionCategory_dictText">
				  <u--input
				  	disabled
				  	placeholder="请选择岗位序列"
				  	v-model="basicForm.positionCategory_dictText"
				  	border="surround"
				  	suffixIcon="arrow-down-fill"
				  	:suffixIconStyle="{color: '#B2B2B2'}"
				  ></u--input>
				</u-form-item>
				<u-form-item
					label="岗位名称"
					prop="positionId_dictText"
					:borderBottom="false"
				>
					<u--input
						disabled
						placeholder="请选择岗位名称"
						v-model="basicForm.positionId_dictText"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="毕业院校"
					prop="graduatedFrom"
					:borderBottom="false"
				>
					<u--input
						v-model="basicForm.graduatedFrom"
						disabled
						placeholder="请输入毕业院校"
						border="surround"
					></u--input>
				</u-form-item>
				<u-form-item
					label="学历"
					prop="highestDegree_dictText"
					:borderBottom="false"
				>
					<u--input
						disabled
						placeholder="请选择学历"
						v-model="basicForm.highestDegree_dictText"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="所学专业"
					prop="major"
					:borderBottom="false"
				>
					<u--input
						v-model="basicForm.major"
						disabled
						placeholder="请输入所学专业"
						border="surround"
					></u--input>
				</u-form-item>
				<u-form-item
					label="毕业时间"
					prop="graduationDate"
					:borderBottom="false"
				>
					<u--input
						v-model="basicForm.graduationDate"
						disabled
						placeholder="请选择毕业时间"
						border="surround"
						suffixIcon="calendar-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="所在部门"
					prop="departmentId_dictText"
					:borderBottom="false"
				>
					<u--input
						disabled
						placeholder="请选择所在部门"
						v-model="basicForm.departmentId_dictText"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="入职日期"
					prop="entryTime"
					:borderBottom="false"
					required
				>
					<u--input
						v-model="basicForm.entryTime"
						disabled
						placeholder="请选择入职日期"
						border="surround"
						suffixIcon="calendar-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="职称"
					prop="professionalTitle"
					:borderBottom="false"
				>
					<u--input
						v-model="basicForm.professionalTitle"
						disabled
						placeholder="请输入职称"
						border="surround"
					></u--input>
				</u-form-item>
				<u-form-item
					label="职业资格"
					prop="professionalQualification"
					:borderBottom="false"
					required
				>
					<u--input
						v-model="basicForm.professionalQualification"
						disabled
						placeholder="请输入职业资格"
						border="surround"
					></u--input>
				</u-form-item>
				<u-form-item
					label="所属团队"
					prop="teamId_dictText"
					:borderBottom="false"
					required
				>
					<u--input
						disabled
						placeholder="请选择所属团队"
						v-model="basicForm.teamId_dictText"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="非相关工作经验（年）"
					prop="workExperience"
					:borderBottom="false"
				>
					<u--input
						v-model="basicForm.workExperience"
						disabled
						placeholder="请输入非相关工作经验（年）"
						border="surround"
					></u--input>
				</u-form-item>
				<u-form-item
					label="相关工作经验（年）"
					prop="relatedWorkExperience"
					:borderBottom="false"
					required
				>
					<u--input
						v-model="basicForm.relatedWorkExperience"
						disabled
						placeholder="请输入相关工作经验（年）"
						border="surround"
					></u--input>
				</u-form-item>
				<u-form-item
					label="申请转正日期"
					prop="regularTime"
					:borderBottom="false"
					required
				>
					<u--input
						v-model="basicForm.regularTime"
						disabled
						placeholder="请选择申请转正日期"
						border="surround"
						suffixIcon="calendar-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="试用期工资标准(元)"
					prop="salary"
					:borderBottom="false"
					required
				>
					<u--input
						type="number"
						v-model="basicForm.salary"
						placeholder="请输入试用期工资标准"
						border="surround"
					></u--input>
				</u-form-item>
				<u-form-item
					label="预计转正后薪级"
					prop="regularScale"
					:borderBottom="false"
					required
				>
					<h-select-input-tag
					  class="w-100"
					  v-model="basicForm.regularScale"
					  objectField="basicForm.regularScale"
					  placeholder="请选择预计转正后薪级"
					  border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"
					  dictName="erp_pay_grade,salary_grade,id,del_flag = 0 and audit_status=2"
					></h-select-input-tag>
				</u-form-item>
				<u-form-item
					label="转正后确认薪级"
					prop="salaryScale"
					:borderBottom="false"
					required
				>
					<h-select-input-tag
					  class="w-100"
					  v-model="basicForm.salaryScale"
					  objectField="basicForm.salaryScale"
					  placeholder="请选择转正后确认薪级"
					  border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"
					  dictName="erp_pay_grade,salary_grade,id,del_flag = 0 and audit_status=2"
					></h-select-input-tag>
				</u-form-item>
				<u-form-item
					label="公积金基数(元)"
					prop="providentFundBase"
					:borderBottom="false"
					required
				>
					<u--input type="number" placeholder="请输入公积金基数(元)" v-model="basicForm.providentFundBase"></u--input>
				</u-form-item>
				<u-form-item
					label="公积金购买单位"
					prop="providentFundUnit"
					:borderBottom="false"
					required
				>
					<h-select-company-input-popup
					  style="width: 100%"
					  v-model="basicForm.providentFundUnit"
					  placeholder="请选择公积金购买单位"
					  border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"
					></h-select-company-input-popup>
				</u-form-item>
				<u-form-item
					label="其他约定事项"
					prop="remark"
					:borderBottom="false"
					ref="item1"
				>
					<u--textarea
						disabled
						v-model="basicForm.remark"
						confirmType="done"
						placeholder="请填写其他约定事项"
					></u--textarea>
				</u-form-item>
			</view>
			<!-- <view class="basic-style">
				<view class="basic-title basic-border">员工试用期考核信息</view>
				<u-form-item
					label=""
					prop="regularDetail"
					:borderBottom="false"
				>
				<view
					@click="onFormClick"
					style="font-size: 14px;
						width: 100%;
						line-height: 14px;
						color: #0000ff;
						margin-top: 20rpx;
						display: flex;
						align-items: center;
						justify-content: center;
					"
				 	><text>查看员工试用期考核表</text></view>
				</u-form-item>
			</view> -->
		</u--form>
		
		<!-- 附件 -->
		<view class="basic-style">
			<view class="basic-title basic-border">附件信息</view>
			<view class="" style="width: 100%;">
				<!-- <h-upload-file v-model="basicForm.attachment" :isIcon="false"></h-upload-file> -->
				<file-list v-if="basicForm.attachment" v-model="basicForm.attachment" :isDelete="false"></file-list>
			</view>
		</view>
		
		<view class="space-x-1 px-1 btn_position">
			<backButton  @onSubmit="onSubmit" :disabled="!isBtn" :nodeObj="nodeObj" :model="model" :resultObj="resultObj"></backButton>
		</view>
		<view style="height: 100rpx;"></view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
import fileList from './components/fileList.vue'
import backButton from '@/components/backButton.vue'
import {
	queryByIdHrEmployeeRegular, // 根据id查询信息
	getProcessTaskTransInfo, // 流程流转
	editHrEmployeeRegular // 编辑财务收款申请单审批流程
} from '@/api/index.js'
import {
	BASE_URL
} from '@/utils/baseUrl.js'
import { convertCurrency } from '@/utils/MoneyConvert' // 金额大写转换
export default {
	components: {
		fileList,
		backButton
	},
	data() {
		var validatorFlag = async (rule,value,callback)=>{
			if(value){
				if(!this.flag){
					callback('请保存试用期考核表！')
					return;
				}
				callback()
			}
			callback()
		};
		return {
			resultObj: {}, // 流程图流转信息
			isBtn: false, // 
			isSubmit: false,
			birthday: '',
			basicForm: {
				billNo: '',
				relatedWorkExperience: '',
				regularScale: '',
				professionalQualification: '',
				salary: '',
				teamId: '',
				entryTime: '',
				regularTime: '',
				salaryScale: '',
				providentFundBase: '',
				providentFundUnit: '',
				// regularDetail: {}
			},
			nodeObj: {},
			tabvalue:'',
			id: '', // 详情id值
			model: {},
			rules: {
				relatedWorkExperience: [
					{ required: true, message: '请输入相关工作经验!'},
				],
				regularScale: [
					{ required: true, message: '请选择预计转正后薪级!' }
				],
				professionalQualification: [
					{ required: true, message: '请输入职业资格!'},
				],
				salary: [
					{ type: 'number', required: true, message: '请输入试用期工资标准!', trigger: ['blur', 'change'] },
					{ required: true, pattern: /^(([1-9][0-9]*|0)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的试用期工资标准!', trigger: ['blur', 'change']},
				],
				teamId: [
					{ required: true, message: '请选择所属团队!'},
				],
				entryTime: [
					{ required: true, message: '您暂无入职日期，请联系HR!' }
				],
				regularTime: [
					{ required: true, message: '请选择申请转正日期!' }
				],
				salaryScale: [
					{ required: true, message: '请选择薪级!' }
				],
				providentFundBase: [
					{ type: 'number', required: true, message: '请输入公积金基数!', trigger: ['blur', 'change'] },
					{ required: true, pattern: /^(([1-9][0-9]*|0)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的公积金基数!', trigger: [ 'change'] }
				],
				providentFundUnit: [
					{ required: true, message: '请选择公积金购买单位!' }
				],
				// regularDetail: [
				// 	{ required: true, message: '请完善员工试用期考核表!' },
				// 	{  validator: validatorFlag },
				// ],
			},
			flag: false
		};
	},
	onLoad(options) {
		var that = this
		this.model = JSON.parse(decodeURIComponent(options.item))
		// #ifdef APP-NVUE
			var eventChannel = this.$scope.eventChannel; // 兼容APP-NVUE
		// #endif
		// #ifndef APP-NVUE
			var eventChannel = this.getOpenerEventChannel();
		// #endif
		// 监听sendMessage事件，获取上一页面通过eventChannel传送到当前页面的数据
		eventChannel.on('sendMessage', function(data) {
			that.tabvalue = data.tabvalue
			that.nodeObj = JSON.parse(decodeURIComponent(data.nodeObj))
			that.loadData(that.nodeObj.dataId)
			that.id = that.nodeObj.dataId
			that.getProcessTaskTrans(that.model.id)
		})
	},
	methods: {
		loadData(id){
			queryByIdHrEmployeeRegular({ id }).then(res => {
				if(res.success){
					this.isBtn = true // 可以点按钮
					if (res.result.birthday) {
						var arr = res.result.birthday.split(' ')
						this.birthday = arr[0]
					}
					this.basicForm = res.result
					// if(this.basicForm.regularDetail){
					// 	let evaluating = this.basicForm.regularDetail.evaluating
					// 	if(evaluating){
					// 		this.basicForm.regularDetail.evaluating = JSON.parse(evaluating);
					// 	}
					// 	if(this.basicForm.regularDetail.id){
					// 		this.flag = true;
					// 	}
					// }
				} else {
					this.$refs.uToast.show({
						message: res.message,
						type: 'error'
					})
				}
			})
		},
		// 点击跳转考核信息
		onFormClick () {
			var _that = this
			uni.navigateTo({
				url:`/pages/synergy/employeeEvaluationForm`,
				success: function(res){
					res.eventChannel.emit('sendMessage',{ data: _that.basicForm,disableSubmit: false })
				},
				events: {
					acceptMessage: function(data) {
						_that.flag = data.flag
						// _that.basicForm.regularDetail=Object.assign({},data.data);
					},
				}
			})
		},
		isJsonString(str) {
			try {
				if (typeof JSON.parse(str) == "object") {
					return true;
				}
			} catch(e) {
				// error
			}
			return false;
		},
		
		// 查询流程流转信息 -- 获取下一节点信息
		getProcessTaskTrans(taskId){
			getProcessTaskTransInfo({ taskId }).then(res => {
				if(res.success){
					this.resultObj = res.result
				} else {
					this.$refs.uToast.show({
						message: res.message,
						type: 'error'
					})
				}
			}).catch(err => {
				console.log(err);
			})
		},
		// 点击提交
		onSubmit () {
			var _this = this
			this.$refs.hmform.validate().then(res => {
				if(res){
					// let evaluating = this.basicForm.regularDetail.evaluating
					// if(evaluating && !this.isJsonString(evaluating)){
					// 	this.basicForm.regularDetail.evaluating = JSON.stringify(evaluating);
					// }
					editHrEmployeeRegular(this.basicForm).then(res => {
						if (res.success) {
							this.$refs.uToast.show({
								message: '提交成功',
								type: 'success',
								complete () {
									_this.onAudit()
								}
							})
							this.isSubmit = true
							
						} else {
							this.$refs.uToast.show({
								message: res.message,
								type: 'error'
							})
						}
					})
				}
			})
		},
		
		onAudit() {
			if (!this.isSubmit) {
				uni.showToast({
					title: '请完善表单后审核',
					icon: 'none'
				})
				return false
			}
			var that = this
			uni.navigateTo({
				url: '/pages/synergy/erpHrEmployeeRegularBillList'+`?item=${encodeURIComponent(JSON.stringify(this.model).replace(/%/g, '%25'))}`,
				success: function(data) {
					// 通过eventChannel向被打开页面传送数据
					var params = {
						nodeObj: encodeURIComponent(JSON.stringify(that.nodeObj).replace(/%/g, '%25')),
						tabvalue: that.tabvalue
					}
					data.eventChannel.emit('sendMessage', params)
				},
				fail: function(err) {
					this.$refs.uToast.show({
						message: '请联系管理员配置',
						type: 'error'
					})
				}
			})
		}
	}
};
</script>

<style lang="scss" scoped>
@import url("@/assets/inputStyle.scss");
// 评测信息
.info-title{
	font-size: 28rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: #171717;
	line-height: 40rpx;
	padding-bottom: 16rpx;
}

// 评测结果
.result-style{
	font-size: 24rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: #B2B2B2;
}

.inforamtion{
	margin-top: 10rpx;
	padding: 10rpx;
	border-radius: 15rpx;
	box-shadow: 0px 4px 20px 0px rgba(0,0,0,0.1);
}
</style>